package com.eshop.modules.user.rest;

import org.springframework.web.bind.annotation.DeleteMapping;
import com.eshop.modules.aop.ForbidSubmit;
import java.util.Collection;
import java.util.ArrayList;
import java.util.Arrays;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.data.domain.Pageable;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import io.swagger.annotations.ApiOperation;
import com.eshop.logging.aop.log.Log;
import java.io.IOException;
import com.eshop.modules.user.service.dto.UserRechargeDto;
import com.eshop.modules.user.service.dto.UserRechargeQueryCriteria;
import javax.servlet.http.HttpServletResponse;
import com.eshop.dozer.service.IGenerator;
import com.eshop.modules.user.service.UserRechargeService;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import io.swagger.annotations.Api;

@Api(tags = { "充值管理管理" })
@RestController
@RequestMapping({ "/api/yxUserRecharge" })
public class UserRechargeController
{
    private final UserRechargeService userRechargeService;
    private final IGenerator generator;
    
    public UserRechargeController(final UserRechargeService userRechargeService, final IGenerator generator) {
        this.userRechargeService = userRechargeService;
        this.generator = generator;
    }
    
    @Log("导出数据")
    @ApiOperation("导出数据")
    @GetMapping({ "/download" })
    @PreAuthorize("@el.check('yxUserRecharge:list')")
    public void download(final HttpServletResponse response, final UserRechargeQueryCriteria criteria) throws IOException {
        this.userRechargeService.download(this.generator.convert(this.userRechargeService.queryAll(criteria), (Class)UserRechargeDto.class), response);
    }
    
    @GetMapping
    @Log("查询充值管理")
    @ApiOperation("查询充值管理")
    @PreAuthorize("@el.check('yxUserRecharge:list')")
    public ResponseEntity<Object> getYxUserRecharges(final UserRechargeQueryCriteria criteria, final Pageable pageable) {
        return new ResponseEntity(this.userRechargeService.queryAll(criteria, pageable), HttpStatus.OK);
    }
    
    @ForbidSubmit
    @Log("删除充值管理")
    @ApiOperation("删除充值管理")
    @PreAuthorize("@el.check('yxUserRecharge:del')")
    @DeleteMapping
    public ResponseEntity<Object> deleteAll(@RequestBody final Integer[] ids) {
        this.userRechargeService.removeByIds((Collection)new ArrayList(Arrays.asList(ids)));
        return new ResponseEntity(HttpStatus.OK);
    }
}
